package com.ithrima.activiti.day03.activiti;


import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;

/**
 *    全部流程挂机与激活
 */
public class SuspendProcessInstance {

    public static void main(String[] args) {
        //1. 得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2、得到RepositoryService对象
        RepositoryService repositoryService = processEngine.getRepositoryService();
        //3. 查询流程实例
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                .processDefinitionKey("myProcess_1").singleResult();
        //5. 得到当前流程定义是否都是暂停状态
        boolean suspended = processDefinition.isSuspended();
        //  判断
        if (suspended) {
            // 暂定状态，可以激活
            repositoryService.activateProcessDefinitionById(processDefinition.getId(),true,null);
            System.out.println("流程激活："+processDefinition.getId());
        }else {
            // 挂起操作
            repositoryService.suspendProcessDefinitionById(processDefinition.getId(),false,null);
            System.out.println("流程挂起："+processDefinition.getId());
        }
    }

}
